const state = {
  msg: "",
  alert: false,
  type: "info",
  time: 2000,
};
const mutations = {
  // eslint-disable-next-line no-shadow
  SET_MSG_STATE: (state, data) => {
    const keys = Object.keys(data);
    state.alert = true;
    keys.forEach((key) => {
      state[key] = data[key];
    });
    if (!keys.includes("time")) {
      // eslint-disable-next-line no-param-reassign
      data.time = state.time;
    }
    setTimeout(() => {
      state.alert = false;
    }, data.time);
  },
};
const getters = {
  Msgmsg: () => state.msg,
  Msgalert: () => state.alert,
  Msgtype: () => state.type,
};
const actions = {
  msg({ commit }, data) {
    commit("SET_MSG_STATE", data);
  },
};
export default {
  state,
  mutations,
  getters,
  actions,
};
